
<h1>Tasks</h1>
<table border = 0 width ="20">
    <?php foreach ($tasks as $task): ?>
        <?php
        if (($task['tasks_has_users']['status'] == 'pending') && ($task['tasks']['status'] == 'incomplete') && ($task['tasks_has_users']['permissionLevel'] == 'assignee')) {
            ?>
            <TABLE BORDER=2 BORDERCOLOR=red>
                <td>

                    <?php echo $this->Html->link($task['tasks']['originalMessage'], array('action' => 'view', $task['tasks']['taskID'])) ?> <br></br>
                    <?php echo ' Assigned by ' . $task['tasks']['sentBy'] ?> <?php
            echo $this->Form->create('Task');
            echo $this->Form->input('status', array('style' => 'width:500px', 'type' => 'hidden', 'value' => 'accepted'));
            echo $this->Form->input('taskID', array('style' => 'width:500px', 'type' => 'hidden', 'value' => $task['tasks']['taskID']));
            echo $this->Form->input('action', array('style' => 'width:500px', 'type' => 'hidden', 'value' => 'accept'));
                    ?> <?php echo $this->Form->end('Accept Task'); ?>  <?php
            echo $this->Form->create('Task');
            echo $this->Form->input('status', array('style' => 'width:500px', 'type' => 'hidden', 'value' => 'rejected'));
            echo $this->Form->input('taskID', array('style' => 'width:500px', 'type' => 'hidden', 'value' => $task['tasks']['taskID']));
            echo $this->Form->input('action', array('style' => 'width:500px', 'type' => 'hidden', 'value' => 'reject'));
                    ?>  <?php echo $this->Form->end('Reject Task'); ?>  <?php
            echo $this->Form->create('Task');
            echo $this->Form->input('status', array('style' => 'width:500px', 'type' => 'hidden', 'value' => 'rejected'));
            echo $this->Form->input('taskID', array('style' => 'width:500px', 'type' => 'hidden', 'value' => $task['tasks']['taskID']));
            echo $this->Form->input('action', array('style' => 'width:500px', 'type' => 'hidden', 'value' => 'reassign'));
                    ?>  <?php echo $this->Form->end('Reassign Task'); ?>  </tr>
                    <br></br>  
                </td></tr>
                <?php
            } else if (($task['tasks_has_users']['status'] == 'pending') && ($task['tasks']['status'] == 'complete') && ($task['tasks_has_users']['permissionLevel'] == 'assignee')) {
                ?>
                <TABLE BORDER=2 BORDERCOLOR=red>
                    <td>
                        <?php echo $this->Html->link($task['tasks']['originalMessage'], array('action' => 'view', $task['tasks']['taskID'])) ?> <br></br> <?php
                        ?> <br></br>  <?php echo ' Assigned by ' . $task['tasks']['sentBy'] ?>
                    </td></tr><
                    <?php
                } else if (($task['tasks']['status'] == 'complete') && ($task['tasks_has_users']['status'] == 'accepted')) {
                    ?>
                    <TABLE BORDER=2 BORDERCOLOR=green>
                        <td>
                            <?php echo $this->Html->link($task['tasks']['originalMessage'], array('action' => 'view', $task['tasks']['taskID'])) ?> <br></br> <?php
                            ?> <br></br>  <?php echo ' Assigned by ' . $task['tasks']['sentBy'] ?>
                        </td></tr>
                        <?php
                    } else if (($task['tasks']['status'] == 'complete') && ($task['tasks_has_users']['permissionLevel'] == 'reassigner')) {
                        ?>
                        <TABLE BORDER=2 BORDERCOLOR=green>
                            <td>
                                <?php echo $this->Html->link($task['tasks']['originalMessage'], array('action' => 'view', $task['tasks']['taskID'])) ?> <br></br> <?php
                                ?> <br></br>  <?php echo ' Assigned by ' . $task['tasks']['sentBy'] ?>
                            </td></tr>
                            <?php
                        } else if (($task['tasks']['status'] == 'incomplete') && ($task['tasks_has_users']['permissionLevel'] == 'reassigner')) {
                            ?>
                            <TABLE BORDER=2 BORDERCOLOR=purple>
                                <td>
                                    <?php echo $this->Html->link($task['tasks']['originalMessage'], array('action' => 'view', $task['tasks']['taskID'])) ?> <br></br> <?php ?> <br></br>  <?php echo ' Assigned by ' . $task['tasks']['sentBy'] ?>
                                </td></tr>
                                <?php
                            } else if (($task['tasks_has_users']['status'] == 'accepted') && $task['tasks']['status'] == 'incomplete') {
                                ?>
                                <TABLE BORDER=2 BORDERCOLOR=orange>
                                    <td>
                                        <?php echo $this->Html->link($task['tasks']['originalMessage'], array('action' => 'view', $task['tasks']['taskID'])) ?> <br></br> <?php
                                if ($task['tasks_has_users']['permissionLevel'] == 'assignee') {
                                    echo $this->Form->create('Task');
                                    echo $this->Form->input('status', array('style' => 'width:500px', 'type' => 'hidden', 'value' => 'complete'));
                                    echo $this->Form->input('taskID', array('style' => 'width:500px', 'type' => 'hidden', 'value' => $task['tasks']['taskID']));
                                    echo $this->Form->input('action', array('style' => 'width:500px', 'type' => 'hidden', 'value' => 'reassign'));
                                    echo $this->Form->end('Reassign Task');
                                    echo $this->Form->create('Task');
                                    echo $this->Form->input('status', array('style' => 'width:500px', 'type' => 'hidden', 'value' => 'complete'));
                                    echo $this->Form->input('taskID', array('style' => 'width:500px', 'type' => 'hidden', 'value' => $task['tasks']['taskID']));
                                    echo $this->Form->input('action', array('style' => 'width:500px', 'type' => 'hidden', 'value' => 'end'));
                                    echo $this->Form->end('End Task');
                                }
                                        ?> <br></br>  <?php echo ' Assigned by ' . $task['tasks']['sentBy'] ?>
                                    </td></tr> <?php } else if (($task['tasks_has_users']['status'] == 'rejected') && ($task['tasks_has_users']['permissionLevel'] == 'assignee')) { ?>
                                    <TABLE BORDER=2 BORDERCOLOR=#659EC7>
                                        <td>
                                            <?php echo $this->Html->link($task['tasks']['originalMessage'], array('action' => 'view', $task['tasks']['taskID'])) ?> <br></br> <?php ?> <br></br>  <?php
                                    echo ' Assigned by ' . $task['tasks']['sentBy'];
                                    echo $this->Form->create('Task');
                                    echo $this->Form->input('status', array('style' => 'width:500px', 'type' => 'hidden', 'value' => 'complete'));
                                    echo $this->Form->input('taskID', array('style' => 'width:500px', 'type' => 'hidden', 'value' => $task['tasks']['taskID']));
                                    echo $this->Form->input('action', array('style' => 'width:500px', 'type' => 'hidden', 'value' => 'reassign'));
                                    echo $this->Form->end('Reassign Task');
                                            ?>
                                        </td></tr> <?php
                                }
                            endforeach;
                                    ?>
                            </table>